package com.hnkywl.sts.service.organ;

import com.hnkywl.sts.dao.organ.BgjhdwDao;
import com.hnkywl.sts.entity.organ.Bgjhdw;
import com.hnkywl.sts.util.ReflectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: lenovo
 * Date: 13-3-21
 * Time: 下午5:13
 * To change this template use File | Settings | File Templates.
 */
@Service
public class BgjhdwService {
    private BgjhdwDao bgjhdwDao;

    /**
     * 查询保供计划单位明细
     *
     * @param id 名称
     * @return
     */
    @Transactional
    public Bgjhdw findBgjhdwDetail(Long id) {
        return this.bgjhdwDao.get(id);
    }

    /**
     * 保存保供计划单位信息
     *
     * @param
     * @return
     */
    @Transactional
    public void saveBgjhdw(Bgjhdw bgjhdw) {
        bgjhdw.setSfqy(true);
        bgjhdw.setDateCreated(new Date());
        bgjhdw.setLastUpdated(bgjhdw.getDateCreated());
        this.bgjhdwDao.save(bgjhdw);
    }

    /**
     * 删除保供计划单位
     *
     * @param id 岗位ID
     * @return
     */
    @Transactional
    public void deleteBgjhdw(Long id) {
        Bgjhdw bgjhdw = bgjhdwDao.get(id);
        bgjhdw.setDeleted(1);
        bgjhdw.setLastUpdated(new Date());
        this.bgjhdwDao.save(bgjhdw);
    }

    /**
     * 更新保供计划单位
     *
     * @param
     * @return
     */
    @Transactional
    public void updateBgjhdw(Bgjhdw bgjhdw) throws RuntimeException {
        Bgjhdw clone = bgjhdwDao.get(bgjhdw.getId());
        clone = (Bgjhdw) ReflectionUtils.getInstance(clone, bgjhdw);
        clone.setLastUpdated(new Date());
        this.bgjhdwDao.save(clone);
    }

    @Autowired
    public void setBgjhdwDao(BgjhdwDao bgjhdwDao) {
        this.bgjhdwDao = bgjhdwDao;
    }
}
